package com.ws.dao;

import com.ws.bean.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeDao {

    @Select("select employee.*, depart.dname from employee, depart where employee.did = depart.did and ename = #{ename} and epass=#{epass} and estatus = 0")
    Employee login(@Param("ename") String ename,@Param("epass") String epass);

    @Select("select employee.*, depart.dname from employee, depart where employee.did = depart.did and estatus = #{estatus} limit #{page}, #{size}")
    List<Employee> findByPage(@Param("estatus") String estatus,@Param("page") int page,@Param("size") int size);

    @Select("select count(*) from employee where estatus=#{estatus}")
    int totalLine(String estatus);

    @Insert("insert into employee values(null, #{ename}, #{epass}, #{realname}, #{esex}, now(), null, #{position}, #{sal}, 0, #{did})")
    void addEmp(Employee employee);

    @Select("select * from employee where eid = #{eid}")
    Employee findByEid(String eid);

    @Update("update employee set ename = #{ename}, epass = #{epass}, realname = #{realname}, esex = #{esex}, position = #{position}, sal = #{sal}, did = #{did} where eid = #{eid}")
    void editUser(Employee employee);

    @Update("update employee set estatus = #{estatus}, entrydate = now(), leavedate = null  where eid = #{eid}")
    void updateEmp2(@Param("estatus") int estatus,@Param("eid") int eid);

    @Update("update employee set estatus = #{estatus}, leavedate= now() where eid = #{eid}")
    void updateEmp1(int estatus, int eid);

    @Select("select employee.*, depart.dname from employee, depart where employee.realname like concat('%',#{realname}, '%') " +
            "and employee.did = depart.did and employee.estatus = #{estatus}")
    List<Employee> findByName(@Param("realname") String realname,@Param("estatus") String estatus);

    @Select("select eid from employee where position = #{position}")
    List<Integer> findEidByPosition(@Param("position") int position);

    @Select("select eid from employee where did = #{did} and position = 2")
    List<Integer> findIdsByDid(int did);

    @Update("update employee set epass = #{epass} where eid = #{eid}")
    void updatePwd(@Param("eid") int eid,@Param("epass") String epass);

    @Update("update employee set photo=#{photo} where eid = #{eid}")
    void updatePhoto(@Param("eid") int eid, @Param("photo") String photo);


//    @Select("select count(*) from employee where realname like concat('%',#{realname}, '%') and estatus = #{estatus}")
//    int totalLine2(String realname, String estatus);
}
